var prefix = "/webapi/teacher/dimclass";
var myGrid;

//批量删除按鈕
 function batchRemove() {
    myGrid.batchRemove();
}

//顯示增加對話框按鈕
function showAddModel() {
    myGrid.showAddModel();
}

//顯示更新對話框按鈕
function showUpdateModel(id) {
    myGrid.showUpdateModel(id);
}

//查看日志跳转页面按钮
function jumpToLogInfo(id) {
    window.location.href="/teacher/labloginfo/list?id="+id;
}


//顯示更新對話框按鈕
function searchTable() {
    myGrid.loadTable();
}

//导出Excel按鈕
function outExcel() {
    myGrid.exportExcel();
}

$(function () {
    var options = {
        ctrfix: "/teacher/dimclass",//当前控制器
        srForm: '#srForm',//查询表单名
        AddDlgTitle: '新增学期学年',
        updateDlgTitle: '更新学期学年',

        tableId: '#classTable',
        recordId:'id',
        //formId:'#formRole',//弹出对话框的表单id
        //dlgID:'#modal-Role',
        sort: 'id',
        direct: 'desc',

        deleteURL: function(){
            return prefix + "/batchDelete";
        },
        listURL: function(){
            return prefix + "/getByPage";
        },
        outExcel: function(){
          return prefix + "/exportExcel";
        },
        columns:[
            {
                checkbox: true
            },
            {
                field: 'id', // 列字段名
                title: '序号', // 列标题
                sortable:true
            },
            {
                field: 'courseName',
                title : '课程名',
                sortable:true
            },
            {
                field: 'className',
                title : '班级名',
                sortable:true
            },
            {
                field: 'classPersonNumber',
                title : '人数',
                sortable:true
            },
            {
                field: 'termName',
                title : '学期',
                sortable:true
            },
            {
                field: 'createTime',
                title : '建立时间',
                sortable:true
            },

            {
                data: null,
                title: '操作',
                width: '150px',
                formatter: function (data,  row, meta) {
                    var operators = '<div class="btn-groups">'
                        +'<a href="#" class="btn btn-icon ion-ios-compose-outline icon-lg add-tooltip" title="编辑" onclick=showUpdateModel('
                        +row.id+',"'+options.updateDlgTitle+'"); title="'
                        +options.updateDlgTitle+'"></a>'
                        +'<a href="#" class="btn btn-icon ion-ios-eye-outline icon-lg add-tooltip" title="查看日志" onclick=jumpToLogInfo('
                        +row.id+',"'+options.updateDlgTitle+'"); title="'
                        +options.updateDlgTitle+'"></a>'
                        +'</div>';
                    return operators;
                }
            }
          ]
    }

    if (s_edit_h == ''){
        options.editable = true;
    } else {
        options.editable = false;
    }



    myGrid = new gridViewModel(options);
    myGrid.init();

    $.ajax({
        method: "POST",
        url: "/webapi/teacher/dimterm/getAll",
        data: {}
    }).done(function( rs ) {
            if(rs.code>=0){
                //成功，取data
                var len=rs.data.length;
                html="<option></option>";
                for(var i=0;i<len;i++){

                    html+="<option value='"+rs.data[i].id+"'>"+rs.data[i].name+"</option>";

                }
                $("#srtermId").html(html);
                $("#srtermId").chosen({width: "200px",
                    no_results_text: "没有找到结果!",
                    search_contains: true});
            }else{
                alert(rs.msg);
            }
        });
});



